﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VOL.Core.DBManager;
using VOL.Core.Extensions;
using VOL.Core.ManageUser;
using VOL.Core.Services;
using VOL.Core.Utilities;
using VOL.Entity.DomainModels;
using VOL.MyTable.Repositories;
using syio = System.IO;
/// <summary>
/// 自定义api调用
/// 主要用于费用控制系统打印使用
/// </summary>
namespace VOL.WebApi.Controllers.MyTable.customer_api
{
    [Route("api/customer")]
    [ApiController]
    public class customer_one : Controller
    {

        string logpic_base64 = "<img src=''/>";
        /// <summary>
        /// 申请解除可用额度限制
        /// </summary>
        /// <returns></returns>
        [HttpPost, Route("save_shenqi"), AllowAnonymous]
        public Object save_shenqi(string options)
        {
            WebResponseContent _webResponse = new WebResponseContent();
            Hashtable rtn_hst = new Hashtable();
            //string sql = "";
            //Console.WriteLine(content);
            
            dynamic queryjson = JsonConvert.DeserializeObject(options);
            //Console.Write(queryjson);
            string loginid = UserContext.Current.GetUserInfo(UserContext.Current.UserId).UserName;//用户登录账户
            
            Fk_reimfloat rf = new Fk_reimfloat();//dd为打印log图片
            try
            {
                using(var db = DBServerProvider.DbContext)
                {
                    rf.username = loginid;
                    rf.stepid = queryjson._stepid;
                    rf.typeid = queryjson._typeid;
                    rf.bdatetime = DateTime.Now;
                    rf.remark = queryjson._content;
                    rf.reimid = queryjson._reimid;// CustomHelper.JsonRegex(queryjson._reimid);
                    rf.node_type = "sqj";//类型为sqj(申请解除可用的限制)，sqj_ok表示同意解除可用额度限制
                                         //}
                                         //db.Add<Fk_reimfloat>(rf);
                    db.Add(rf);

                    db.SaveChanges();//注意不能放在foreach循环里面
                }
               
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
            }
           
            
            //DbSet<Fk_reimfloat> reimfloat = db.Set<Fk_reimfloat>();
            
            //Console.WriteLine(rf.fk_reimfloat_id);
            rtn_hst.Add("newdata", rf);
            
            return Json(_webResponse.OK("保存成功", rtn_hst));
            //return rtn_hst;
        }
        /// <summary>
        /// 回款通知书打印
        /// </summary>
        /// <param name="_reimds_str"></param>
        /// <returns></returns>
        [HttpPost, Route("hktzs_print"), AllowAnonymous]
        public string hktzs_print(string? _reimds_str)
        {
            string html_str = "";
            string totao_html_str = "";
            string[] _reimds_array= _reimds_str.Split(",");
            //Console.WriteLine(_reimds_str);
            //Console.WriteLine(_reimds_array.Length);

            
            List<int> lint = new List<int>();//C#没有不定长数组这种东西，一般建议用Llist泛型，当你需要里再转成数ToArray();
            for (int i = 0; i <= _reimds_array.Length - 1; i++)
            {
                //_reimds[i] = int.Parse(_reimds_array[i]);
                lint.Add(int.Parse(_reimds_array[i]));
                //Console.WriteLine(int.Parse(_reimds_array[i]));
            }
            int[] _reimds = lint.ToArray();
            string filepath = @"Template//cutomer_print_template//hktzs_print//hktzs_template.html";
            /*string path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;//获取应用程序运行的目录
            UTF8Encoding utf8 = new UTF8Encoding();
            //FileHelper.ReadFile(@"Template\\AppHtml\\news.html");
            
            string temp = filepath.MapPath().ReplacePath();
            syio.StreamReader file = null;
            try
            {
                file= new syio.StreamReader(temp, utf8);
                //Console.WriteLine(temp);
                html_str = file.ReadToEnd();
            }
            catch//一定要释放，否则再次写入不了
            {
                file.Close();
                file.Dispose();
            }*/
            html_str=CustomHelper.read_local_file(filepath);
            string html_str_rows= CustomHelper.read_local_file(@"Template//cutomer_print_template//hktzs_print//hktzs_template_rows.html");
            //dd为打印log图片
           
            //string dd = "";
            
            string fyf = " <div style='page-break-after:always'></div>";//分页字符串
            string old_html_str = html_str.Replace("@image@", logpic_base64);//打印log图片base64

            List<Fk_reim> _reimlist = DBServerProvider.DbContext.Set<Fk_reim>()
           .Where(t => (_reimds.Contains(t.reim_id))).ToList();

            //in操作如果用参数，不能用()
            string sqlstr = $"select (select stepname from sys_step where stepid=fk_reimfloat.stepid) stepname, (select usertruename from sys_user where username=fk_reimfloat.username) realname,bdatetime,remark row_remark,reimid from fk_reimfloat where reimid in @_reimds and node_type!='key'";
            List<dynamic> _reimfloatlist = DBServerProvider.SqlDapper.QueryList<dynamic>(sqlstr, new { _reimds }).ToList();

            sqlstr = $"select b.*,(select fei_typename from fei_typelist a where a.racct=b.fei_type) racct from fk_reimlist b where b.reim_id in @_reimds";
            List<dynamic> reim_mx = DBServerProvider.SqlDapper.QueryList<dynamic>(sqlstr, new { _reimds }).ToList();

            //Console.WriteLine(_reimfloatlist);

            /* List<Fk_reimfloat> _reimfloatlist = DBServerProvider.DbContext.Set<Fk_reimfloat>()
            .Where(t => _reimds.Contains(t.reimid??0)).ToList();*/

            string bdatetime = "";
            string fj_num = "";
            string skr = "";
            string contract = "";
            string fkcontent = "";
            string total_j_big = "";
            string total_j = "";
            string ykcontent = "";
            string yk_je_big = "";
            string yk_je = "";
            string check_je_big = "";
            string check_je = "";
            string fkfs = "";
            string bank = "";
            string cardno = "";
            string remark = "";
            string sf_je = "";
            string sf_je_big = "";
            string racct = "";
            Logger.Error("打印回款通知书"+DateTime.Now.ToString("yyyy-MM-dd H:mm:ss"));
            //row
            /*string stepname = "";
            string realname = "";
            string bdatetime = "";
            string row_remark = "";*/
            //Console.WriteLine("zu:" + _reimds.Length);
            for (int i=0;i<= _reimds.Length-1; i++)
            {
                //Console.WriteLine("dfdf");
                //Console.WriteLine(_reimds[i]);
                html_str = old_html_str;
                bdatetime = ((DateTime)_reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.bdatetime).FirstOrDefault()).ToLongDateString();
                fj_num = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.fj_num).FirstOrDefault().ToString();
                skr = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.skr).FirstOrDefault();
                contract = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.contract).FirstOrDefault();
                fkcontent = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.fkcontent).FirstOrDefault();
                total_j_big = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.total_j ?? 0).FirstOrDefault().ToString();////
                total_j_big = CustomHelper.MoneyToUpper(total_j_big);
                total_j = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.total_j ?? 0).FirstOrDefault().ToString();
                ykcontent = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.ykcontent).FirstOrDefault();
                yk_je_big = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.yk_je ?? 0).FirstOrDefault().ToString();//
                yk_je_big = CustomHelper.MoneyToUpper(yk_je_big);
                yk_je = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.yk_je ?? 0).FirstOrDefault().ToString();
                check_je_big = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.check_je ?? 0).FirstOrDefault().ToString();//
                check_je_big = CustomHelper.MoneyToUpper(check_je_big);
                check_je = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.check_je).FirstOrDefault().ToString();
                fkfs = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.fkfs).FirstOrDefault();
                bank = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.bank).FirstOrDefault();
                cardno = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.cardno).FirstOrDefault();
                remark = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.remark).FirstOrDefault();

                sf_je = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.sf_je ?? 0).FirstOrDefault().ToString();//
                sf_je_big = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.sf_je ?? 0).FirstOrDefault().ToString();//
                sf_je_big = CustomHelper.MoneyToUpper(sf_je_big);
                racct = reim_mx.Where(w => w.reim_id == _reimds[i]).Select(s => s.racct).FirstOrDefault().ToString();

                html_str = html_str.Replace("@skr@", skr);
                html_str = html_str.Replace("@contract@", contract);
                html_str = html_str.Replace("@fkcontent@", fkcontent);
                html_str = html_str.Replace("@total_j_big@", total_j_big);
                html_str = html_str.Replace("@total_j@", total_j);
                html_str = html_str.Replace("@ykcontent@", ykcontent);
                html_str = html_str.Replace("@yk_je_big@", yk_je_big);
                html_str = html_str.Replace("@yk_je@", yk_je);
                html_str = html_str.Replace("@check_je_big@", check_je_big);
                html_str = html_str.Replace("@check_je@", check_je);
                html_str = html_str.Replace("@fkfs@", fkfs);
                html_str = html_str.Replace("@bank@", bank);
                html_str = html_str.Replace("@cardno@", cardno);
                html_str = html_str.Replace("@remark@", remark);
                html_str = html_str.Replace("@bdatetime@", bdatetime);
                html_str = html_str.Replace("@fj_num@", fj_num);
                html_str = html_str.Replace("@sf_je@", sf_je);
                html_str = html_str.Replace("@sf_je_big@", sf_je_big);
                html_str = html_str.Replace("@racct@", racct);
                string hktzs_rows = "";
                for(int ii=0;ii<= _reimfloatlist.Count - 1; ii++)
                {
                    if (_reimds[i] == _reimfloatlist[ii].reimid)
                    {
                        string rowstr = html_str_rows;
                        rowstr = rowstr.Replace("@stepname@", _reimfloatlist[ii].stepname);
                        rowstr = rowstr.Replace("@realname@", _reimfloatlist[ii].realname);
                        rowstr = rowstr.Replace("@bdatetime@", _reimfloatlist[ii].bdatetime.ToString());
                        rowstr = rowstr.Replace("@row_remark@", _reimfloatlist[ii].row_remark);
                        hktzs_rows = hktzs_rows + rowstr;
                    }
                   
                   // Console.WriteLine(_reimfloatlist[ii].stepname);
                  
                }
                html_str = html_str.Replace("@hktzs_rows@", hktzs_rows);
                
                totao_html_str = totao_html_str + html_str + fyf;//分页符

            }
            
            
            return totao_html_str;
        }
        /// <summary>
        /// 差旅报销单打印取数
        /// </summary>
        /// <param name="_reimds_str"></param>
        /// <returns></returns>
        [HttpPost, Route("cnbxd_print"), AllowAnonymous]
        public string cnbxd_print(string? _reimds_str)
        {
            string html_str = "";
            string totao_html_str = "";
            string[] _reimds_array = _reimds_str.Split(",");
            List<int> lint = new List<int>();//C#没有不定长数组这种东西，一般建议用Llist泛型，当你需要里再转成数ToArray();
            for (int i = 0; i <= _reimds_array.Length - 1; i++)
            {
                //_reimds[i] = int.Parse(_reimds_array[i]);
                lint.Add(int.Parse(_reimds_array[i]));
                //Console.WriteLine(int.Parse(_reimds_array[i]));
            }
            int[] _reimds = lint.ToArray();
            string filepath = @"Template//cutomer_print_template//cnbxd_print//cnbxd_template.html";
            html_str = CustomHelper.read_local_file(filepath);
            string html_mx_rows = CustomHelper.read_local_file(@"Template//cutomer_print_template//cnbxd_print//cnmx_template_rows.html");
            string html_str_rows = CustomHelper.read_local_file(@"Template//cutomer_print_template//cnbxd_print//cnsh_template_rows.html");
            

            //string dd = "";

            string fyf = " <div style='page-break-after:always'></div>";//分页字符串
            string old_html_str = html_str.Replace("@image@", logpic_base64);//打印log图片base64

           
            List<Fk_reim> _reimlist = DBServerProvider.DbContext.Set<Fk_reim>()
           .Where(t => (_reimds.Contains(t.reim_id))).ToList();


            List<Fk_reimlist> _reimitemlist = DBServerProvider.DbContext.Set<Fk_reimlist>()
          .Where(t => _reimds.Contains((int)(t.reim_id))).ToList();//需要转一下（int）,否则报int[]不包含contain函数

            List<fk_depart> _deparlist = DBServerProvider.DbContext.Set<fk_depart>().Where(w => (_reimlist.Select(s => s.depid_oa).ToArray().Contains(w.depid_oa))).ToList();


            //in操作如果用参数，不能用()
            string sqlstr = $"select (select stepname from sys_step where stepid=fk_reimfloat.stepid) stepname, (select usertruename from sys_user where username=fk_reimfloat.username) realname,bdatetime,remark row_remark,reimid from fk_reimfloat where reimid in @_reimds and node_type!='key'";
            List<dynamic> _reimfloatlist = DBServerProvider.SqlDapper.QueryList<dynamic>(sqlstr, new { _reimds }).ToList();

            string depid_oa = "";
            string remark = "";
            string skr = "";
            string bank = "";
            string cardno = "";
            string check_je_big = "";
            string check_je = "";
            string bdatetime = "";
            string fj_num = "";
            string total_j_big = "";
            string total_j = "";

            /*string cc_bdate = "";
            string cc_edate = "";
            string b_dd = "";
            string e_dd = "";
            string bz_je = "";
            string jt_tax = "";
            string jt_je = "";
            string zz_tax = "";
            string zz_je = "";
            string other_tax = "";
            string other_je = "";
            string tax = "";
            string je = "";*/

            for (int i = 0; i <= _reimds.Length - 1; i++)
            {
                //Console.WriteLine("dfdf");
                //Console.WriteLine(_reimds[i]);
                html_str = old_html_str;
                depid_oa = _deparlist.Where(w => w.depid_oa == _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.depid_oa).FirstOrDefault()).Select(s => s.depname_oa).FirstOrDefault();
                skr = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.skr).FirstOrDefault();
                remark = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.remark).FirstOrDefault();
                bank = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.bank).FirstOrDefault();
                cardno = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.cardno).FirstOrDefault();
                bdatetime = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.bdatetime).FirstOrDefault().ToString();
                fj_num = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.fj_num).FirstOrDefault().ToString();
               

                total_j_big = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.total_j ?? 0).FirstOrDefault().ToString();////
                total_j_big = CustomHelper.MoneyToUpper(total_j_big);
                total_j = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.total_j ?? 0).FirstOrDefault().ToString();

                check_je_big = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.check_je ?? 0).FirstOrDefault().ToString();//
                check_je_big = CustomHelper.MoneyToUpper(check_je_big);
                check_je = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.check_je).FirstOrDefault().ToString();

                html_str = html_str.Replace("@bdatetime@", bdatetime);
                html_str = html_str.Replace("@fj_num@", fj_num);
                html_str = html_str.Replace("@depid_oa@", depid_oa);
                html_str = html_str.Replace("@skr@", skr);
                html_str = html_str.Replace("@remark@", remark);
                html_str = html_str.Replace("@bank@", bank);
                html_str = html_str.Replace("@cardno@", cardno);
                html_str = html_str.Replace("@check_je_big@", check_je_big);
                html_str = html_str.Replace("@check_je@", check_je);
                html_str = html_str.Replace("@total_j_big@", total_j_big);
                html_str = html_str.Replace("@total_j@", total_j);

                
                string cnmx_rows = "";
                for (int ii = 0; ii <= _reimitemlist.Count - 1 ; ii++)
                {
                    if (_reimitemlist[ii].reim_id == _reimds[i])
                    {
 
                        string rowstr = html_mx_rows;
                        rowstr = rowstr.Replace("@cc_bdate@", Convert.ToDateTime(_reimitemlist[ii].cc_bdate).ToString("yyyy-MM-dd"));
                        rowstr = rowstr.Replace("@cc_edate@", Convert.ToDateTime(_reimitemlist[ii].cc_edate).ToString("yyyy-MM-dd"));
                        rowstr = rowstr.Replace("@t_num@", _reimitemlist[ii].t_num.ToString());
                        rowstr = rowstr.Replace("@b_dd@", _reimitemlist[ii].b_dd??"".ToString());

                        rowstr = rowstr.Replace("@e_dd@", _reimitemlist[ii].e_dd??"".ToString());
                        rowstr = rowstr.Replace("@bz_je@", _reimitemlist[ii].bz_je.ToString());
                        rowstr = rowstr.Replace("@jt_tax@", _reimitemlist[ii].jt_tax.ToString());
                        rowstr = rowstr.Replace("@jt_je@", _reimitemlist[ii].jt_je.ToString());

                        rowstr = rowstr.Replace("@zz_tax@", _reimitemlist[ii].zz_tax.ToString());
                        rowstr = rowstr.Replace("@zz_je@", _reimitemlist[ii].zz_je.ToString());
                        rowstr = rowstr.Replace("@other_tax@", _reimitemlist[ii].other_tax.ToString());
                        rowstr = rowstr.Replace("@other_je@", _reimitemlist[ii].other_je.ToString());

                        rowstr = rowstr.Replace("@tax@", _reimitemlist[ii].tax.ToString());
                        rowstr = rowstr.Replace("@je@", _reimitemlist[ii].je.ToString());
                        cnmx_rows = cnmx_rows + rowstr;
                    }
                    // Console.WriteLine(_reimfloatlist[ii].stepname);
                }

                string hktzs_rows = "";
                for (int ii = 0; ii <= _reimfloatlist.Count - 1; ii++)
                {
                    if (_reimds[i] == _reimfloatlist[ii].reimid)
                    {
                        string rowstr = html_str_rows;
                        rowstr = rowstr.Replace("@stepname@", _reimfloatlist[ii].stepname);
                        rowstr = rowstr.Replace("@realname@", _reimfloatlist[ii].realname);
                        rowstr = rowstr.Replace("@bdatetime@", _reimfloatlist[ii].bdatetime.ToString());
                        rowstr = rowstr.Replace("@row_remark@", _reimfloatlist[ii].row_remark);
                        hktzs_rows = hktzs_rows + rowstr;
                        // Console.WriteLine(_reimfloatlist[ii].stepname);
                    }
                }
                html_str = html_str.Replace("@cnsh_rows@", hktzs_rows);
                html_str = html_str.Replace("@cnmx_rows@", cnmx_rows);
                totao_html_str = totao_html_str + html_str + fyf;//分页符

            }
            return totao_html_str;
        }

        /// <summary>
        /// 费用单报销
        /// </summary>
        /// <param name="_reimds_str"></param>
        /// <returns></returns>
        [HttpPost, Route("fybxd_print"), AllowAnonymous]
        public string fybxd_print(string? _reimds_str)
        {
            string html_str = "";
            string totao_html_str = "";
            string[] _reimds_array = _reimds_str.Split(",");
            List<int> lint = new List<int>();//C#没有不定长数组这种东西，一般建议用Llist泛型，当你需要里再转成数ToArray();
            for (int i = 0; i <= _reimds_array.Length - 1; i++)
            {
                //_reimds[i] = int.Parse(_reimds_array[i]);
                lint.Add(int.Parse(_reimds_array[i]));
                //Console.WriteLine(int.Parse(_reimds_array[i]));
            }
            int[] _reimds = lint.ToArray();
            string filepath = @"Template//cutomer_print_template//fybxd_print//fybxd_template.html";
            html_str = CustomHelper.read_local_file(filepath);
            string html_str_rows = CustomHelper.read_local_file(@"Template//cutomer_print_template//fybxd_print//fymx_template_rows.html");
            string html_str_sh_rows = CustomHelper.read_local_file(@"Template//cutomer_print_template//fybxd_print//fysh_template_rows.html");
            //dd为打印log图片
            string dd = logpic_base64;
            //string dd = "";

            string fyf = " <div style='page-break-after:always'></div>";//分页字符串
            string old_html_str = html_str.Replace("@image@", dd);//打印log图片base64

            List<Fk_reim> _reimlist = DBServerProvider.DbContext.Set<Fk_reim>()
           .Where(t => (_reimds.Contains(t.reim_id))).ToList();

            IQueryable<Fei_typelist> _km_query = Fei_typelistRepository.//科目
            Instance.FindAsIQueryable(t => (t.company_oa_id == 9000));//9000和8000的科目是一样的

            IQueryable<Fk_cntr> _cntr_query = Fk_cntrRepository.//成本中心
              Instance.FindAsIQueryable(t => (true));

            IQueryable<Fk_reimlist> _reimitemlist = DBServerProvider.DbContext.Set<Fk_reimlist>()
         .Where(t => _reimds.Contains((int)(t.reim_id)));//需要转一下（int）,否则报int[]不包含contain函数

            IQueryable<dynamic> all_reimlist = from q in _reimitemlist

                                               join q2 in _km_query on q.fei_type equals q2.racct into q2_temp
                                               from q2_out in q2_temp.DefaultIfEmpty()

                                               join q3 in _cntr_query on q.rcntr equals q3.rcntr_no into q3_temp
                                               from q3_out in q3_temp.DefaultIfEmpty()

                                               orderby q.reimlist_id ascending
                                               select new
                                               {
                                                   q2_out.fei_typename,
                                                   q3_out.rcntr,
                                                   q
                                               };
            List<dynamic> all_rlist = all_reimlist.ToList();
            List<fk_depart> _deparlist = DBServerProvider.DbContext.Set<fk_depart>().Where(w => (_reimlist.Select(s => s.depid_oa).ToArray().Contains(w.depid_oa))).ToList();

            //in操作如果用参数，不能用()
            string sqlstr = $"select (select stepname from sys_step where stepid=fk_reimfloat.stepid) stepname, (select usertruename from sys_user where username=fk_reimfloat.username) realname,bdatetime,remark row_remark,reimid from fk_reimfloat where reimid in @_reimds and node_type!='key'";
            List<dynamic> _reimfloatlist = DBServerProvider.SqlDapper.QueryList<dynamic>(sqlstr, new { _reimds }).ToList();
            string depid_oa = "";
            string remark = "";
            string skr = "";
            string bank = "";
            string cardno = "";
            string check_je_big = "";
            string check_je = "";
            string bdatetime = "";
            string fj_num = "";
            string total_j_big = "";
            string total_j = "";
            for (int i = 0; i <= _reimds.Length - 1; i++)
            {
                html_str = old_html_str;
                depid_oa = _deparlist.Where(w => w.depid_oa == _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.depid_oa).FirstOrDefault()).Select(s => s.depname_oa).FirstOrDefault();
                skr = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.skr).FirstOrDefault();
                remark = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.remark).FirstOrDefault();
                bank = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.bank).FirstOrDefault();
                cardno = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.cardno).FirstOrDefault();
                bdatetime = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.bdatetime).FirstOrDefault().ToString();
                fj_num = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.fj_num).FirstOrDefault().ToString();


                total_j_big = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.total_j ?? 0).FirstOrDefault().ToString();////
                total_j_big = CustomHelper.MoneyToUpper(total_j_big);
                total_j = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.total_j ?? 0).FirstOrDefault().ToString();

                check_je_big = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.check_je ?? 0).FirstOrDefault().ToString();//
                check_je_big = CustomHelper.MoneyToUpper(check_je_big);
                check_je = _reimlist.Where(w => w.reim_id == _reimds[i]).Select(s => s.check_je).FirstOrDefault().ToString();

                html_str = html_str.Replace("@bdatetime@", bdatetime);
                html_str = html_str.Replace("@fj_num@", fj_num);
                html_str = html_str.Replace("@depid_oa@", depid_oa);
                html_str = html_str.Replace("@skr@", skr);
                html_str = html_str.Replace("@remark@", remark);
                html_str = html_str.Replace("@bank@", bank);
                html_str = html_str.Replace("@cardno@", cardno);
                html_str = html_str.Replace("@check_je_big@", check_je_big);
                html_str = html_str.Replace("@check_je@", check_je);
                html_str = html_str.Replace("@total_j_big@", total_j_big);
                html_str = html_str.Replace("@total_j@", total_j);

                
                string fymx_rows = "";
                for (int ii = 0; ii <= all_rlist.Count-1; ii++)
                {
                   // Console.WriteLine(all_rlist[ii]);
                    //continue;
                    if (all_rlist[ii].q.reim_id == _reimds[i])
                    {
                        string rowstr = html_str_rows;
                        rowstr = rowstr.Replace("@fei_typename@", all_rlist[ii].fei_typename).ToString();
                        rowstr = rowstr.Replace("@rcntr@", all_rlist[ii].rcntr).ToString();
                        rowstr = rowstr.Replace("@je@", (all_rlist[ii].q.je??"").ToString());

                        fymx_rows = fymx_rows + rowstr;
                    }
                    // Console.WriteLine(_reimfloatlist[ii].stepname);
                }

                string fysh_rows = "";
                for (int ii = 0; ii <= _reimfloatlist.Count - 1; ii++)
                {
                    if (_reimds[i] == _reimfloatlist[ii].reimid)
                    {
                        string rowstr = html_str_sh_rows;
                        rowstr = rowstr.Replace("@stepname@", _reimfloatlist[ii].stepname);
                        rowstr = rowstr.Replace("@realname@", _reimfloatlist[ii].realname);
                        rowstr = rowstr.Replace("@bdatetime@", _reimfloatlist[ii].bdatetime.ToString());
                        rowstr = rowstr.Replace("@row_remark@", _reimfloatlist[ii].row_remark);
                        fysh_rows = fysh_rows + rowstr;
                        // Console.WriteLine(_reimfloatlist[ii].stepname);
                    }
                }
                html_str = html_str.Replace("@fysh_rows@", fysh_rows);
                html_str = html_str.Replace("@fymx_rows@", fymx_rows);
                
                totao_html_str = totao_html_str + html_str + fyf;//分页符

            }
            return totao_html_str;
        }
    }
}
